<?php
class User extends AppModel {

	var $name = 'User';
	var $actsAs = array('Acl' => 'requester');
	
	function afterSave($created) {
        if (!$created) {
            $parent = $this->parentNode();
            $parent = $this->node($parent);
            $node = $this->node();
            $aro = $node[0];
            $aro['Aro']['parent_id'] = $parent[0]['Aro']['id'];
            $this->Aro->save($aro);
        }
}
	
	
	var $validate = array(
		'mi_no' => array('alphanumeric'),
		'user_details_id' => array('numeric'),
		'clg_bool' => array('boolean')
	);

	//The Associations below have been created with all possible keys, those that are not needed can be removed
	var $belongsTo = array(
		'Clgs' => array(
			'className' => 'Clg',
			'foreignKey' => 'clgs_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Groups' => array(
			'className' => 'Group',
			'foreignKey' => 'groups_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

	var $hasOne = array(
		'user_details' => array(
			'className' => 'userDetails',
			'foreignKey' => 'users_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);
	function parentNode() {
    if (!$this->id && empty($this->data)) {
        return null;
    }
    $data = $this->data;
    if (empty($this->data)) {
        $data = $this->read();
    }
    if (!$data['User']['group_id']) {
        return null;
    } else {
        return array('Group' => array('id' => $data['User']['group_id']));
    }
}

}
?>